<template>
  <el-scrollbar class="form-panel enterprise">
    <el-form :model="params" class="demo-form-inline" ref="params" :rules="rules" label-position="top">
      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item :label="$t('certification.enterprise.firmName')" prop="fullName">
            <el-input v-model="params.fullName" disabled clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('certification.enterprise.firmEnName')" prop="fullNameEn">
            <el-input
              v-model="params.fullNameEn"
              clearable
              maxlength="50"
              :placeholder="$t('certification.enterprise.enNamePlaceholder')"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('certification.enterprise.firmShortName')" prop="shortName">
            <el-input
              v-model="params.shortName"
              clearable
              maxlength="50"
              :placeholder="$t('certification.enterprise.shortNamePlaceholder')"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('certification.enterprise.firmAttribute')" prop="enterpriseAttribute">
            <x-select
              :placeholder="$t('certification.enterprise.attributePlaceholder')"
              v-model="params.enterpriseAttribute"
              :options="dictOptions['srm_supplier_info.enterprise_attribute']"
              style="width: 100%"
            />
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item :label="$t('certification.enterprise.allCreditCode')" prop="taxId">
            <el-input
              v-model="params.taxId"
              clearable
              maxlength="50"
              :placeholder="$t('certification.enterprise.codePlaceholder')"
            ></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item :label="$t('certification.enterprise.currency')" prop="registerCapitalCurrency">
            <x-select
              :placeholder="$t('certification.enterprise.currencyPlaceholder')"
              v-model="params.registerCapitalCurrency"
              :options="dictOptions['currency']"
              style="width: 100%"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('certification.enterprise.registerCapital')" prop="registerCapital">
            <el-input
              :placeholder="$t('certification.enterprise.capitalPlaceholder')"
              v-model="params.registerCapital"
              clearable
            >
              <template slot="append">{{ $t('certification.enterprise.tenThousandYuan') }}</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('certification.enterprise.firmWebsit')" prop="website">
            <el-input
              :placeholder="$t('certification.enterprise.websitPlaceholder')"
              v-model="params.website"
              clearable
            >
              <template slot="prepend">Htpp://</template>
              <template slot="append">.com</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('certification.enterprise.firmEmail')" prop="email">
            <el-input
              v-model="params.email"
              clearable
              maxlength="50"
              :placeholder="$t('certification.enterprise.emailPlaceholder')"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('certification.enterprise.firmPhone')" prop="telephone">
            <el-input
              v-model="params.telephone"
              clearable
              maxlength="50"
              :placeholder="$t('certification.enterprise.phonePlaceholder')"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('certification.enterprise.firmFax')" prop="fax">
            <el-input
              v-model="params.fax"
              clearable
              maxlength="50"
              :placeholder="$t('certification.enterprise.faxPlaceholder')"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('certification.enterprise.staffNumber')" prop="employeeNumber">
            <el-input
              v-model="params.employeeNumber"
              clearable
              maxlength="50"
              :placeholder="$t('certification.enterprise.staffNumberPlaceholder')"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('certification.enterprise.workersNumber')" prop="technicianNumber">
            <el-input
              v-model="params.technicianNumber"
              clearable
              maxlength="50"
              :placeholder="$t('certification.enterprise.workersPlaceholder')"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('certification.enterprise.firmProperty')" prop="nature">
            <x-select
              :placeholder="$t('certification.enterprise.firmPropertyPlaceholder')"
              v-model="params.nature"
              :options="dictOptions['srm_supplier_info.nature']"
              style="width: 100%"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('certification.enterprise.firmType')" prop="enterpriseType">
            <x-select
              :placeholder="$t('certification.enterprise.firmTypePlaceholder')"
              v-model="params.enterpriseType"
              :options="dictOptions['srm_supplier_info.enterprise_type']"
              style="width: 100%"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('certification.enterprise.country')" prop="country">
            <x-select
              ref="countrySelect"
              :placeholder="$t('certification.enterprise.countryPlaceholder')"
              v-model="params.country"
              :options="dictOptions['country']"
              :attrOption="{
                label: 'areaName',
                value: 'id'
              }"
              style="width: 100%"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item
            :label="$t('certification.enterprise.registeAdrress')"
            prop="address"
            :rules="[
              {
                required: params.country === '105807528965108',
                message: $t('certification.enterprise.adrressPlaceholder'),
                trigger: 'blur'
              }
            ]"
          >
            <x-address-input
              :disabled="params.country && params.country !== '105807528965108'"
              :parent-id="params.country"
              ref="registerTree"
              :addrType="1"
              :placeholder="$t('certification.enterprise.adrressPlaceholder')"
              v-model="params.address"
              style="width: 100%"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item prop="fullAddress" clas="no-label">
            <template #label>&nbsp;&nbsp;</template>
            <el-input
              v-model="params.fullAddress"
              :disabled="params.country !== '105807528965108'"
              :placeholder="$t('certification.enterprise.addressInputPlaceholder')"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('certification.enterprise.economicType')" prop="economicType">
            <x-select
              :placeholder="$t('certification.enterprise.economicTypePlaceholder')"
              v-model="params.economicType"
              :options="dictOptions['srm_supplier_info.economic_type']"
              style="width: 100%"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('certification.enterprise.establishmentTime')" prop="birthTime">
            <el-date-picker
              v-model="params.birthTime"
              type="date"
              :placeholder="$t('certification.enterprise.establishmentTimePlaceholder')"
              style="width: 100%"
              value-format="yyyy-MM-dd"
              format="yyyy-MM-dd"
              default-time="00:00:00"
              :picker-options="pickerOptions"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item
            :label="$t('certification.enterprise.operatingTerm')"
            prop="operatingPeriod"
            :show-message="!isLongTerm"
          >
            <div class="flex-row">
              <el-date-picker
                v-model="params.operatingPeriod"
                :disabled="isLongTerm"
                type="date"
                :placeholder="$t('certification.enterprise.operatingTermPlaceholder')"
                style="width: 100%"
                value-format="yyyy-MM-dd"
                format="yyyy-MM-dd"
                default-time="00:00:00"
                :picker-options="pickerEndOptions"
              >
              </el-date-picker>
              <el-checkbox v-model="isLongTerm" style="margin-left: 10px">{{
                $t('certification.enterprise.longTime')
              }}</el-checkbox>
            </div>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('certification.enterprise.industryClassification')" prop="industry">
            <x-select-tree
              v-model="params.industry"
              ref="selectTree"
              :is-lazy="true"
              :nodeKey="'dictCode'"
              :request-url="'/srm/dict/tree/findTree'"
              :othe-params="{ dictType: 'industry' }"
              :placeholder="$t('certification.enterprise.classificationPlaceholder')"
              :defaultProps="industryProps"
              style="width: 100%"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('certification.enterprise.balanceSheetRatio')" prop="assetLiabilityRatio">
            <el-input
              v-model="params.assetLiabilityRatio"
              :placeholder="$t('certification.enterprise.balanceSheetRatioPlaceholder')"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('certification.enterprise.rturnOnCapital')" prop="returnOnCapital">
            <el-input
              v-model="params.returnOnCapital"
              :placeholder="$t('certification.enterprise.rturnOnCapitalPlaceholder')"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('certification.enterprise.mainBusinessSales')" prop="mainBusinessIncome">
            <el-input
              :placeholder="$t('certification.enterprise.mainBusinessSalesPlaceholder')"
              v-model="params.mainBusinessIncome"
              clearable
            >
              <template slot="append">{{ $t('certification.enterprise.tenThousandYuan') }}</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('certification.enterprise.totalAssets')" prop="totalAssets">
            <el-input
              :placeholder="$t('certification.enterprise.totalAssetsPlaceholder')"
              v-model="params.totalAssets"
              clearable
            >
              <template slot="append">{{ $t('certification.enterprise.tenThousandYuan') }}</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('certification.enterprise.mainType')" prop="mainServeType">
            <x-select-tree
              :placeholder="$t('certification.enterprise.mainTypePlaceholder')"
              v-model="params.mainServeType"
              :options="dictOptions['main_serve_type']"
              :defaultProps="mainServeTypeProps"
              style="width: 100%"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item
            :label="$t('certification.enterprise.serviceArea')"
            prop="mainServeArea"
            :rules="[
              {
                required: params.country === '105807528965108',
                // required: false,
                message: $t('certification.enterprise.serviceAreaPlaceholder'),
                trigger: ['blur', 'change']
              }
            ]"
          >
            <x-address-input
              :disabled="params.country !== '105807528965108'"
              :parent-id="params.country"
              ref="serviceTypeTree"
              :other-params="{
                beginLevel: 1,
                endLevel: 2
              }"
              :configProps="xAddressConfigProps"
              :addrType="3"
              :placeholder="$t('certification.enterprise.serviceAreaPlaceholder')"
              v-model="params.mainServeArea"
              style="width: 100%"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('certification.enterprise.customer')" prop="keyCustomers">
            <el-input
              type="textarea"
              v-model="params.keyCustomers"
              :placeholder="$t('certification.enterprise.customerPlaceholder')"
              clearable
              maxlength="200"
              :autosize="{
                minRows: 3,
                maxRows: 6
              }"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('certification.enterprise.mainGoods')" prop="mainProducts">
            <el-input
              type="textarea"
              v-model="params.mainProducts"
              :placeholder="$t('certification.enterprise.mainGoodsPlaceholder')"
              clearable
              maxlength="200"
              :autosize="{
                minRows: 3,
                maxRows: 6
              }"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('certification.enterprise.businessScope')" prop="businessScope">
            <el-input
              type="textarea"
              :placeholder="$t('certification.enterprise.businessScopePlaceholder')"
              v-model="params.businessScope"
              style="width: 100%"
              maxlength="200"
              :autosize="{
                minRows: 3,
                maxRows: 6
              }"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('certification.enterprise.businessLicense')" prop="licenses">
            <template #label>
              <em class="required-icon"> * </em>
              <span>{{ $t('certification.enterprise.businessLicense') }}</span>
            </template>
            <!-- 执照上传 -->
            <x-upload
              ref="businessFileUpload"
              :edit-flag="true"
              :limit="9"
              :fileSize="20"
              :old-file-list="params.licenses || []"
              :file-type="['jpg', 'jpeg', 'png', 'ppt', 'pptx', 'pdf', 'xls', 'xlsx']"
            >
            </x-upload>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('certification.enterprise.firmSeal')" prop="seals">
            <!-- 公章上传 -->
            <x-upload
              ref="sealUpload"
              :edit-flag="true"
              :limit="1"
              :fileSize="20"
              :old-file-list="params.seals || []"
              :file-type="['jpg', 'jpeg', 'png', 'ppt', 'pptx', 'pdf', 'xls', 'xlsx']"
              :tips="'文件大小不超过30M，文件数量1以内'"
            >
            </x-upload>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('certification.enterprise.whenQualificationLevel')" prop="qualifyFlag">
            <x-radio-group :list-data="dictOptions['system.whether']" v-model="params.qualifyFlag"></x-radio-group>
          </el-form-item>
        </el-col>
        <div v-if="isQualify">
          <el-col :span="8">
            <el-form-item
              :label="$t('certification.enterprise.qualificationCertificate')"
              prop="qualificationCertificate"
            >
              <el-input
                v-model="params.qualificationCertificate"
                clearable
                maxlength="50"
                :placeholder="$t('certification.enterprise.qualificationCertificatePlaceholder')"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('certification.enterprise.qualificationClass')" prop="qualificationCategory">
              <x-select
                :placeholder="$t('certification.enterprise.qualificationClassPlaceholder')"
                v-model="params.qualificationCategory"
                :options="dictOptions['srm_supplier_info.qualification_category']"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('certification.enterprise.QualificationLevel')" prop="qualificationLevel">
              <el-input
                v-model="params.qualificationLevel"
                :placeholder="$t('certification.enterprise.qualificationLevelPlaceholder')"
                maxlength="50"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('certification.enterprise.certificationScope')" prop="certificationScope">
              <el-input
                v-model="params.certificationScope"
                maxlength="50"
                :placeholder="$t('certification.enterprise.certificationScopePlaceholder')"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('certification.enterprise.qualificationSubject')" prop="qualificationSubject">
              <el-input
                v-model="params.qualificationSubject"
                :placeholder="$t('certification.enterprise.qualificationSubjectPlaceholder')"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('certification.enterprise.currentlyValid')" prop="currentValidFlag">
              <x-radio-group
                :list-data="dictOptions['system.whether']"
                v-model="params.currentValidFlag"
              ></x-radio-group>
            </el-form-item>
          </el-col>
        </div>
      </el-row>
    </el-form>
  </el-scrollbar>
</template>
<script>
  import {
    omit,
    checkEmail,
    checkMobilePhone,
    checkFloatNumber,
    checkFixPhone,
    checkFixNumber,
    cloneDeep
  } from '@package/utils'
  import { apiPostAddBase, apiGetBase, apiPostUpdateBase } from '../api'
  import { EnumApiCode } from '../../../../../../globalEnum.js'

  export default {
    name: 'EnterpriseInfo',
    props: {
      dictOptions: {
        type: Object,
        default: () => ({})
      },
      supplierId: {
        type: String
      }
    },
    data() {
      return {
        params: {
          fullName: '',
          fullNameEn: '',
          shortName: '',
          enterpriseAttribute: '',
          taxId: '',
          registerCapitalCurrency: '',
          registerCapital: '',
          website: '',
          email: '',
          telephone: '',
          fax: '',
          employeeNumber: '',
          technicianNumber: '',
          country: '',
          fullAddress: '',
          address: [],
          nature: '',
          enterpriseType: '',
          economicType: '',
          birthTime: '',
          operatingPeriod: '',
          industry: {
            dictName: '',
            dictCode: ''
          },
          industryCode: '',
          assetLiabilityRatio: '',
          returnOnCapital: '',
          mainBusinessIncome: '',
          totalAssets: '',
          mainServeType: '',
          mainServeArea: [],
          keyCustomers: '',
          mainProducts: '',
          businessScope: '',
          qualifyFlag: '0',
          qualificationCertificate: '',
          qualificationCategory: '',
          qualificationLevel: '',
          certificationScope: '',
          qualificationSubject: '',
          currentValidFlag: '',
          city: '',
          licenses: [],
          seals: []
        },
        rules: {
          enterpriseAttribute: [
            {
              required: true,
              message: this.$t('certification.enterprise.attributePlaceholder'),
              trigger: ['blur', 'change']
            }
          ],
          taxId: [{ required: true, message: this.$t('certification.enterprise.codePlaceholder'), trigger: 'blur' }],
          registerCapitalCurrency: [
            {
              required: true,
              message: this.$t('certification.enterprise.currencyPlaceholder'),
              trigger: ['blur', 'change']
            }
          ],
          registerCapital: [
            { required: true, message: this.$t('certification.enterprise.capitalPlaceholder'), trigger: 'blur' },
            { validator: this.validateMoney, trigger: 'blur' }
          ],
          email: [
            { required: true, message: this.$t('certification.enterprise.emailPlaceholder'), trigger: 'blur' },
            { validator: this.validateEmail, trigger: 'blur' }
          ],
          telephone: [
            { required: true, message: this.$t('certification.enterprise.phonePlaceholder'), trigger: 'blur' },
            { validator: this.validatePhone, trigger: 'blur' }
          ],
          fax: [{ validator: this.vaildFixNumber, trigger: 'blur' }],
          country: [
            {
              required: true,
              message: this.$t('certification.enterprise.countryPlaceholder'),
              trigger: ['blur', 'change']
            }
          ],
          address: [
            {
              required: true,
              validator: this.validateAddress
              // trigger: ['blur', 'change']
            }
          ],
          enterpriseType: [
            {
              required: true,
              message: this.$t('certification.enterprise.firmTypePlaceholder'),
              trigger: ['blur', 'change']
            }
          ],
          nature: [
            {
              required: true,
              message: this.$t('certification.enterprise.firmPropertyPlaceholder'),
              trigger: ['blur', 'change']
            }
          ],
          economicType: [
            {
              required: true,
              message: this.$t('certification.enterprise.economicTypePlaceholder'),
              trigger: ['blur', 'change']
            }
          ],
          birthTime: [
            {
              required: true,
              message: this.$t('certification.enterprise.establishmentTimePlaceholder'),
              trigger: 'blur'
            }
          ],
          operatingPeriod: [
            {
              required: true,
              validator: this.validateOperating,
              trigger: 'blur'
              // trigger: ['blur']
            }
          ],
          industry: [
            {
              required: true,
              validator: this.validInstry,
              // message: this.$t('certification.enterprise.classificationPlaceholder'),
              trigger: 'blur'
            }
          ],
          mainServeType: [
            {
              required: true,
              message: this.$t('certification.enterprise.mainTypePlaceholder'),
              trigger: 'blur'
              // trigger: ['change']
            }
          ],
          keyCustomers: [
            { required: true, message: this.$t('certification.enterprise.customerPlaceholder'), trigger: 'blur' }
          ],
          mainProducts: [
            { required: true, message: this.$t('certification.enterprise.mainGoodsPlaceholder'), trigger: 'blur' }
          ],
          businessScope: [
            { required: true, message: this.$t('certification.enterprise.businessScopePlaceholder'), trigger: 'blur' }
          ],
          qualifyFlag: [
            {
              required: true,
              message: this.$t('certification.enterprise.isQualificationLevelPlaceholder'),
              trigger: ['blur', 'change']
            }
          ],
          qualificationCertificate: [
            {
              required: true,
              message: this.$t('certification.enterprise.qualificationCertificatePlaceholder'),
              trigger: 'blur'
            }
          ],
          certificationScope: [
            {
              required: true,
              message: this.$t('certification.enterprise.certificationScopePlaceholder'),
              trigger: 'blur'
            }
          ],
          qualificationLevel: [
            {
              required: true,
              message: this.$t('certification.enterprise.qualificationLevelPlaceholder'),
              trigger: 'blur'
            }
          ],
          qualificationSubject: [
            {
              required: true,
              message: this.$t('certification.enterprise.qualificationSubjectPlaceholder'),
              trigger: 'blur'
            }
          ],
          currentValidFlag: [
            {
              required: true,
              message: this.$t('certification.enterprise.currentlyValidPlaceholder'),
              trigger: ['blur', 'change']
            }
          ]
          // licenses: [
          //   { required: true, message: this.$t('certification.enterprise.licensePlaceholder'), trigger: 'change' }
          // ]
        },
        isLongTerm: false,
        pickerOptions: {
          disabledDate: (time) => {
            return new Date(time).getTime() > new Date().getTime() - 86400000
          }
        },
        pickerEndOptions: {
          disabledDate: (time) => {
            return new Date(time).getTime() < new Date().getTime() - 86400000
          }
        },
        industryProps: {
          label: 'dictName',
          value: 'dictCode',
          children: 'children'
        },
        mainServeTypeProps: {
          label: 'supplierTypeName',
          children: 'children'
        },
        xAddressConfigProps: {
          multiple: true
        }
      }
    },
    computed: {
      isQualify() {
        return `${this.params.qualifyFlag}` === '1'
      }
    },
    watch: {
      supplierId: {
        handler(val) {
          if (this.supplierId) {
            this.getBaseInfo(this.supplierId)
          }
        },
        immediate: true,
        deep: true
      },
      'params.country': {
        // 针对国外的数据，地址数据及主供区域不录入
        handler(val) {
          if (this.params.country !== '105807528965108' && this.params.country) {
            this.params.address = []
            this.params.fullAddress = ''
            this.params.mainServeArea = []
          }
        },
        immediate: true,
        deep: true
      }
    },
    methods: {
      async getBaseInfo(supplierId) {
        const { data } = await apiGetBase(supplierId)
        this.$nextTick(() => {
          this.params = Object.assign(this.params, cloneDeep(data))
          this.isLongTerm = this.params.operatingPeriod && this.params.operatingPeriod.indexOf('9999') !== -1
          if (this.isLongTerm) {
            this.params.operatingPeriod = ''
          }
          const addressArr = this.params.address
          // 主供区域的省市数据 多选数组
          this.params.mainServeArea = addressArr.filter((v) => {
            return v.addrType === 3
          })
          // 注册地址的省市区数据 数组
          this.params.address = addressArr.filter((v) => {
            return v.addrType === 1
          })
          this.params.fullAddress = addressArr.length ? addressArr[0].address : ''
          this.params.qualifyFlag = this.params.qualifyFlag ? `${this.params.qualifyFlag}` : '0'
          this.params.currentValidFlag += ''
          this.params.industry = {
            dictCode: this.params.industryCode,
            dictName: this.params.industryClassification
          }
          this.$emit('getAuditInfo', this.params)
        })
      },
      // 整合注册地址和主供区域地址数据
      getAddressArr() {
        const addressArr = [
          ...this.params.address.map((v) => {
            return {
              ...v,
              address: this.params.fullAddress,
              addrType: 1,
              country: this.$refs.countrySelect.selectionName,
              countryId: this.params.country
            }
          }),
          ...this.params.mainServeArea.map((v) => {
            return {
              ...v,
              addrType: 3,
              country: this.$refs.countrySelect.selectionName,
              countryId: this.params.country
            }
          })
        ]
        return addressArr.filter((v) => Object.keys(v).length > 4)
      },
      // 经营期限数据整合
      getOperatingPeriodTime() {
        let valTimes = ''
        if (this.isLongTerm) {
          valTimes = '9999-12-31 23:59:59'
        } else {
          valTimes = this.params.operatingPeriod ? `${this.params.operatingPeriod} 23:59:59` : ''
        }
        return valTimes
      },
      handleVaildForm() {
        return new Promise((resolve) => {
          this.$refs.params.validate((valid) => {
            if (valid) {
              const licensesFiles = this.$refs.businessFileUpload.fileList
              if (!licensesFiles?.length) {
                this.$message.error(this.$t('certification.enterprise.licensePlaceholder'))
                return resolve(false)
              }
              resolve(true)
            } else {
              resolve(false)
            }
          })
        })
      },
      onSumit(isVaild = true) {
        return new Promise(async (resolve, reject) => {
          const isSubmit = !isVaild || (await this.handleVaildForm())
          if (isSubmit) {
            const licensesFiles = this.$refs.businessFileUpload.fileList
            const sealsFiles = this.$refs.sealUpload.fileList
            const addressArr = this.getAddressArr()
            const _par = {
              ...omit(this.params, ['fullAddress', 'mainServeArea']),
              birthTime: this.params.birthTime ? `${this.params.birthTime} 23:59:59` : '',
              operatingPeriod: this.getOperatingPeriodTime(),
              licenses: licensesFiles?.length
                ? licensesFiles.map((v) => {
                    return {
                      fileName: v.name || v.fileName,
                      filePath: v.filePath || v.response.data.filePath,
                      fileType: (v.name || v.fileName).slice((v.name || v.fileName).lastIndexOf('.') + 1),
                      remark: v.remark
                    }
                  })
                : [],
              seals: sealsFiles?.length
                ? sealsFiles.map((v) => {
                    return {
                      fileName: v.name || v.fileName,
                      filePath: v.filePath || v.response.data.filePath,
                      fileType: (v.name || v.fileName).slice((v.name || v.fileName).lastIndexOf('.') + 1),
                      remark: v.remark
                    }
                  })
                : [],
              address: addressArr,
              industryCode: this.params.industry.dictCode,
              industryClassification: this.params.industry.dictName,
              id: this.supplierId
            }
            try {
              const { data, code } = 'id' in this.params ? await apiPostUpdateBase(_par) : await apiPostAddBase(_par)
              if (EnumApiCode.Success === code) {
                // this.getDetail()
                resolve(data)
              } else {
                reject()
              }
            } finally {
              reject()
            }
          } else {
            reject()
          }
        })
      },
      validatePhone(rule, value, callback) {
        if (value && value !== '' && !checkMobilePhone(value) && !checkFixPhone(value)) {
          callback(new Error(this.$t('certification.enterprise.pleasePhoneRight')))
        } else {
          callback()
        }
      },
      validateEmail(rule, value, callback) {
        if (value && value !== '' && !checkEmail(value)) {
          callback(new Error(this.$t('certification.enterprise.validateEmailRight')))
        } else {
          callback()
        }
      },
      validateMoney(rule, value, callback) {
        if (value && value !== '' && !checkFloatNumber(value)) {
          callback(new Error(this.$t('certification.enterprise.validateMoneyRight')))
        } else {
          callback()
        }
      },
      vaildFixNumber(rule, value, callback) {
        if (value && value !== '' && !checkFixNumber(value)) {
          callback(new Error(this.$t('certification.enterprise.faxPlaceholder')))
        } else {
          callback()
        }
      },
      validateOperating(rule, value, callback) {
        console.log(!value && !this.isLongTerm, 'llll')
        if (!value && !this.isLongTerm) {
          callback(new Error(this.$t('certification.enterprise.operatingTermPlaceholder')))
        } else {
          callback()
        }
      },
      validInstry(rule, value, callback) {
        if (!value.dictCode) {
          callback(new Error(this.$t('certification.enterprise.classificationPlaceholder')))
        } else {
          callback()
        }
      },
      validateAddress(rule, value, callback) {
        if (!value.length && !value) {
          callback(new Error(this.$t('certification.enterprise.countryPlaceholder')))
        } else {
          callback()
        }
      }
    }
  }
</script>
<style lang="scss" scoped>
  .required-icon {
    margin-right: 4px;
    color: #f56c6c;
  }
</style>
